module Utils where

import List (find)
import Data.Graph.Inductive.Graph (nodes,edges,mkGraph)
import Data.Graph.Inductive.Tree (UGr)

maxList :: [a] -> [a] -> [a]				
maxList l1 l2
    |(length l1) > (length l2) = l1
    |otherwise = l2	

addToSet :: (Eq a) => [a] -> a -> [a]
addToSet list val 
    | val `elem` list = list
    | otherwise       = val:list 

cutStrByCh :: String -> Char -> String
cutStrByCh str ch = takeWhile (/= ch) str

cutStrByChToInt :: String -> Char -> Int
cutStrByChToInt str ch = read $ cutStrByCh str ch
	
--complementary graph
compl:: UGr -> UGr
compl g = mkGraph ([(x,())|x <- nodes g]) 
				  [(begin,end,()) |begin <- (nodes g), end <- (nodes g) , 
					(not (((begin,end) `elem` (edges g)) || ((end,begin) `elem` (edges g) ))) && (begin < end)] 
	